package com.spa.infrastructure.repository.service;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.base.MPJBaseServiceImpl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.spa.infrastructure.util.StringUtils;
import com.spa.infrastructure.repository.condition.FeedbackCondition;
import com.spa.infrastructure.repository.mapper.FeedbackMapper;
import com.spa.infrastructure.repository.po.FeedbackPO;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;
import java.util.List;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

/**
 * domain service
 * 反馈表(Feedback) 
 *
 * @author lig
 * @since 2024-01-11 09:40:27
 */
@Component
public class FeedbackRepositoryService extends MPJBaseServiceImpl<FeedbackMapper, FeedbackPO> {
	

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    public FeedbackPO queryById(Long id) {
		return getById(id);
    }
	
	
	/**
     * 分页查询
     *
     * @return 查询结果
     */
	public Page<FeedbackPO> pageListInfo(FeedbackCondition condition) {
	
		LambdaQueryWrapper<FeedbackPO> wrapper = wrapper(condition);
        return page(Page.of(condition.getCurrent(), condition.getSize()), wrapper);

    }
	
	public List<FeedbackPO> listInfo(FeedbackCondition condition) {
        return list(wrapper(condition));

    }
	
	
	private LambdaQueryWrapper<FeedbackPO> wrapper(FeedbackCondition condition) {
        LambdaQueryWrapper<FeedbackPO> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(ObjectUtils.isNotEmpty(condition.getUserId()),FeedbackPO::getUserId,condition.getUserId());
        wrapper.eq(StringUtils.isNotEmpty(condition.getType()),FeedbackPO::getType,condition.getType());
        wrapper.eq(ObjectUtils.isNotEmpty(condition.getCityId()),FeedbackPO::getCityId,condition.getCityId());
        wrapper.orderByDesc(FeedbackPO::getCreateTime);
        return wrapper;
    }

    

    
}
